/** 数据库相关入口文件 */
// 调用Schema，将Schema注册到mongoose中
require('./schema/User');
require('./schema/InviteCode');
require('./schema/Good');
require('./schema/InventoryLog');
require('./schema/Character');
require('./schema/Log');
require('./schema/ForgetPassword');
require('./schema/GoodClassify');

const mongoose = require('mongoose');

/** 连接mogodb数据库 */
const connect = async () => {
  return new Promise((resolve, reject) => {
    // 连接数据库
    mongoose.connect('mongodb://127.0.0.1:27017/shop-mgr', { useNewUrlParser: true, useUnifiedTopology: true });
    // 数据库打开时，事件
    mongoose.connection.on('open', () => {
      console.log('>>> mogodb 数据库连接成功');
      resolve();
    });
  });
};

module.exports = {
  connect,
};
